home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / BUFFER1.ASM < prev    next >
Assembly Source File  |  1993-05-05  |  4KB  |  116 lines

  1. ;****************************************;
  2. ; WASM Buffered File I/O, Initialization ;
  3. ; By Eric Tauck                          ;
  4. ;                                        ;
  5. ; Defines:                               ;
  6. ;                                        ;
  7. ;   BufAll  allocate buffer              ;
  8. ;   BufRel  release buffer               ;
  9. ;   BufOpn  open buffer file             ;
  10. ;   BufClo  close buffer file            ;
  11. ;                                        ;
  12. ; Requires:                              ;
  13. ;                                        ;
  14. ;   FILE.ASM                             ;
  15. ;   MEMORY.ASM                           ;
  16. ;****************************************;
  17.  
  18. ; Note: All buffer routines (in BUFFER?.ASM) use BX for the
  19. ; buffer record.  BX is guaranteed preserved through these
  20. ; routines (though not through the WASM library routines.).
  21.  
  22.         jmps    _buffer1_end
  23.  
  24. ;--- global data
  25.  
  26. BUFFER_RECORD   EQU     12      ;bytes in buffer record
  27.  
  28. BUFFER_READ     EQU     0       ;reading
  29. BUFFER_WRITE    EQU     1       ;writing
  30. BUFFER_CREATE   EQU     2       ;create (implies writing)
  31.  
  32. ;--- layout of buffer record
  33.  
  34. _BUFFER_CURRENT EQU     0       ;current read/write location (4 bytes)
  35. _BUFFER_BASE    EQU     4       ;base offset (2 bytes)
  36. _BUFFER_SIZE    EQU     6       ;size of buffer (2 bytes)
  37. _BUFFER_BYTES   EQU     8       ;bytes in buffer (2 bytes)
  38. _BUFFER_HANDLE  EQU     10      ;file handle (2 bytes)
  39.  
  40. ;========================================
  41. ; Allocate a buffer.
  42. ;
  43. ; In: BX= buffer record address; AX= size
  44. ;     of buffer.
  45. ;
  46. ; Out: CY= set if error; AL= error code
  47. ;      if error; DX= memory available (if
  48. ;      out of memory).
  49.  
  50. BufAll  PROC    NEAR
  51.         push    bx
  52.         call    MemAll                          ;allocate memory
  53.         pop     bx
  54.         jc      _bfall1
  55.         mov     [bx + _BUFFER_CURRENT + 2], ax  ;buffer segment
  56.         mov     WORD [bx + _BUFFER_BASE], 0     ;buffer base
  57.         mov     [bx + _BUFFER_SIZE], dx         ;buffer size
  58. _bfall1 ret
  59.         ENDP
  60.  
  61. ;========================================
  62. ; Release buffer.
  63. ;
  64. ; In: BX= buffer record address.
  65.  
  66. BufRel  PROC    NEAR
  67.         push    bx
  68.         mov     ax, [bx + _BUFFER_CURRENT + 2]  ;buffer segment
  69.         call    MemRel                          ;release memory
  70.         pop     bx
  71.         ret
  72.         ENDP
  73.  
  74. ;========================================
  75. ; Open a buffer.
  76. ;
  77. ; In: BX= buffer record address; AX=
  78. ;     address of file name; CL= open
  79. ;     type.
  80. ;
  81. ; Out: AL= DOS error code; CY= set if
  82. ;      error.
  83.  
  84. BufOpn  PROC    NEAR
  85.         push    WORD [bx + _BUFFER_BASE]        ;base offset
  86.         pop     WORD [bx + _BUFFER_CURRENT]     ;load to current offset
  87.         mov     WORD [bx + _BUFFER_BYTES], 0    ;zero byte count
  88.  
  89.         push    bx
  90.         mov     dx, OFFSET FilOpn       ;open file routine
  91.         cmp     cl, BUFFER_CREATE       ;check if create new file
  92.         jne     _bfopn1                 ;jump if not
  93.         mov     cl, ATTR_NORMAL         ;create attribute
  94.         mov     dx, OFFSET FilCre       ;create file routine
  95. _bfopn1 call    dx                      ;execute open
  96.         pop     bx
  97.         mov     [bx+_BUFFER_HANDLE], ax ;save handle
  98.         ret
  99.         ENDP
  100.  
  101. ;========================================
  102. ; Close a buffer.
  103. ;
  104. ; Out: AL= DOS error code; CY= set if
  105. ;      error.
  106.  
  107. BufClo  PROC    NEAR
  108.         push    bx
  109.         mov     bx, [bx+_BUFFER_HANDLE] ;load file handle
  110.         call    FilClo                  ;close file
  111.         pop     bx
  112.         ret
  113.         ENDP
  114.  
  115. _buffer1_end
  116.